package com.kfm.base.io.xml;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;

import java.io.*;
import java.net.URLEncoder;

public class Demo03 {

    public static void main(String[] args) {
        String keywords = "猫";
        try {
            keywords = URLEncoder.encode(keywords, "utf-8");
//            HttpResponse response = HttpRequest.get("https://image.baidu.com/search/index?tn=baiduimage&ps=1&ct=201326592&lm=-1&cl=2&nc=1&ie=utf-8&dyTabStr=MTEsMCw2LDMsMSw0LDUsMiw4LDcsOQ%3D%3D&word="+ keywords)
//                    .execute();
            HttpResponse response = HttpRequest.get("https://www3.autoimg.cn/newsdfs/g28/M01/F1/AF/744x0_1_autohomecar__ChxkmmS19OKAI_B2AAZnZShFE0A427.jpg").execute();

            InputStream inputStream = response.bodyStream();

            FileOutputStream fos = new FileOutputStream("d://io/car.jpg");

            fos.write(inputStream.readAllBytes());

            fos.close();
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
